package com.aplink.generic.util.objectrule;

import java.util.ArrayList;

import android.content.pm.PackageManager.NameNotFoundException;

import com.aplink.generic.pojo.GenericObject;

public class TargetCollection extends ArrayList<Target> {
    private static final long serialVersionUID = -5644953729445338838L;
    private String mDefaultActivity;

    public String getDefaultActivity() {
        return this.mDefaultActivity;
    }

    public Target getTargetClass(final GenericObject genericObject)
            throws NameNotFoundException, ClassNotFoundException {
        return handleTarget(genericObject);
    }

    private Target handleTarget(final GenericObject genericObject) {
        if (size() == 1) {
            return get(0);
        }
        for (final Target target : this) {
            if (target.getPage(genericObject) != null) {
                return target.getPage(genericObject);
            }
        }
        return null;
    }

    public void setDefaultActivity(final String defaultActivity) {
        this.mDefaultActivity = defaultActivity;
    }
}
